<?php

class Fencer_Form_Decorator_SimpleLabel extends Zend_Form_Decorator_Abstract
{
    protected $_format = '<label for="%s">%s</label>';
    protected $_tag = 'span';

    public function __construct($options = null)
    {
        if(isset($options['tag'])){
            $this->setTag($options['tag']);
        }
    }

    public function getTag()
    {
        return $this->_tag;
    }

    public function setTag($tag)
    {
        $this->_tag = $tag;
    }

    public function render($content)
    {
        $element = $this->getElement();
        $id      = htmlentities($element->getId());
        $label   = htmlentities($element->getLabel());

        $markup = "<{$this->getTag()}>" . sprintf($this->_format, $id, $label) . "</{$this->getTag()}>";

        $placement = $this->getPlacement();


        $separator = $this->getSeparator();
        switch ($placement) {
            case self::PREPEND:
                return $markup . $separator . $content;
            case self::APPEND:
            default:
                return $content . $separator . $markup;
        }
    }
}
